package com.smedi.ismedi.personnel.core.port.adapter.persistence.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smedi.ismedi.personnel.core.domain.aggregatemodel.PersonSyncFromImis;
import com.smedi.ismedi.personnel.core.domain.repository.PersonSyncFromImisRepository;
import com.smedi.ismedi.web.starter.util.DozerUtil;
import com.smedi.ismedi.personnel.core.port.adapter.persistence.model.PersonSyncFromImisEntity;
import com.smedi.ismedi.personnel.core.port.adapter.persistence.mybatis.mapper.PersonSyncFromImisMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: xulinjun
 * @Date: 2021-6-9 19:49
 */
@Slf4j
@Service
@AllArgsConstructor
public class PersonSyncFromImisRepositoryImpl extends ServiceImpl<PersonSyncFromImisMapper, PersonSyncFromImisEntity> implements PersonSyncFromImisRepository, IService<PersonSyncFromImisEntity> {
    private final DozerUtil dozerUtil;

    @Override
    public void doInsert(List<PersonSyncFromImis> list) {
        List<PersonSyncFromImisEntity> entities = dozerUtil.convertor(list, PersonSyncFromImisEntity.class);
        this.saveBatch(entities);
    }

    @Override
    public void deleteAll() {
        this.getBaseMapper().truncateAll();
    }

    @Override
    public PersonSyncFromImis queryByReferencePersonId(Long referencePersonId) {
        QueryWrapper<PersonSyncFromImisEntity> wrapper = new QueryWrapper();
        wrapper.eq("reference_person_id", referencePersonId);
        PersonSyncFromImisEntity personSyncFromImisEntity = this.getBaseMapper().selectOne(wrapper);
        return dozerUtil.convertor(personSyncFromImisEntity, PersonSyncFromImis.class);
    }
}
